package tongwentongshu.com.app.activity;

import android.os.Bundle;
import android.support.v4.util.ArrayMap;
import android.view.View;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import tongwentongshu.com.app.R;
import tongwentongshu.com.app.bean.AppItem;
import tongwentongshu.com.app.bean.WalletBean;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.network.ResponseSubscriber;
import tongwentongshu.com.app.update.UpdateFractory;

/**
 * Created by XiongBin on 2017/7/21.
 */

public class MyWalletActivity extends BaseActivity {
    @BindView(R.id.tv_shudou_sum)
    TextView shudou;
    @BindView(R.id.tv_deposit_sum)
    TextView deposit;
    private Map<String, String> map;

    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_my_wallet;
    }

    @Override
    protected int getTitleId() {
        return R.string.my_wallet;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        sendCode();
    }

    @OnClick({R.id.rel_shudou, R.id.rel_deposit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rel_shudou:
                startActivity(ShudouActivity.class);
                break;
            case R.id.rel_deposit:
                startActivity(DepositDetailsActivity.class);
                break;
        }
    }

    public void sendCode() {
        map = new ArrayMap<>();
        map.put("token", Cache.getToken());
        UpdateFractory.getBuild()
                .name("WalletCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<WalletBean>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(WalletBean wallet, String msg) {
                        shudou.setText(wallet.getData().getDoudou() + "颗");
                        deposit.setText(wallet.getData().getMoney() + "元");
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });
    }
}
